# !/usr/bin/env python
# coding=utf-8
# @Time    : 2019/11/7 13:46
# @Author  : 6imensiva
# @Site    : https://gitee.com/dimensiva/SeleniumCrapy.git
# @File    : my_return.py
# @Software: PyCharm
# @Version: 2.7.5
import json
from py3_utils.my_code import MyCode


def get_fail(msg=None):
	return MyReturn(code=MyCode.NoPermission, msg=msg, data=None)


def get_success(data):
	return MyReturn(code=MyCode.SUCCESS, msg=None, data=data)


def get_success_msg(m, data):
	return MyReturn(code=MyCode.SUCCESS, msg=m, data=data)


class MyReturn:
	def __init__(self, code, msg=None, data=None):
		self.result = code
		self.msg = msg
		self.data = data

	def to_string(self):
		if isinstance(self.result, MyCode):
			return json.dumps({'result': self.result.value, 'msg': self.msg, 'data': self.data},
			                  ensure_ascii=False)
		else:
			if self.result == True:
				return json.dumps({'result': 1999, 'msg': self.msg, 'data': self.data},
			                  ensure_ascii=False)
			else:
				return json.dumps({'result': -4, 'msg': self.msg, 'data': self.data},
				                  ensure_ascii=False)


if __name__ == '__main__':
	print(MyReturn(False, '已经提交自动审核，请勿重复提交').to_string())
	print(MyReturn(True, 'success', '开始获取保单信息，一共条数据').to_string())
